<template>
  <div class="mobile-kpi-view common-mobile-view">
    <div class="total-kpi">
      <span class="title">当月总绩效</span>
      <span class="value">{{ totalPrice }} 元</span>
    </div>

    <kpi-calendar />

    <draggable-button @click="addClick"/>
  </div>
</template>

<script lang="ts" setup>
import KpiCalendar from '@/components/kpi/KpiCalendar.vue'
import DraggableButton from '@/components/Common/DraggableButton.vue'
import { useKpiStore } from '@/store/kpi.ts'
import { useRouter } from 'vue-router'
import { computed, onMounted } from 'vue'
import { getCurrentMonth, getStartEndDate } from 'vue3-common/utils/dateUtil'

const kpiStore = useKpiStore()
const router = useRouter()

onMounted(async () => {
  const dateInfo = getStartEndDate(getCurrentMonth(), 'month')
  kpiStore.queryInfo.startDate = dateInfo[0]
  kpiStore.queryInfo.endDate = dateInfo[1]
  await kpiStore.refreshInfo()
})

const totalPrice = computed(() => {
  return kpiStore.kpiList.reduce((acc, item) => acc + item.price, 0)
})

const addClick = () => {
  kpiStore.kpiApiType = 'ADD'
  kpiStore.currentKpi = kpiStore.getEmptyKpi()
  router.push({ name: 'KpiDetailId', params: { id: 0 } })
}
</script>

<style lang="scss">
.mobile-kpi-view {
  display: flex;
  flex-direction: column;
  gap: 10px;

  .total-kpi {
    align-self: center;
    display: flex;
    align-items: center;
    gap: 10px;

    .title {
      font-size: 1.5rem;
    }

    .value {
      font-weight: bold;
      font-size: 1.8rem;
      color: var(--el-color-primary);
    }
  }
}
</style>
